package com.mid;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by Lxk on 2019/8/10.
 */
public class Solution462 {

    public int minMoves2(int[] nums) {
        int res = 0;
        if (nums == null || nums.length == 0) {
            return res;
        }
        List<Integer> sortedList = new ArrayList<>();
        for (int val : nums) {
            sortedList.add(val);
        }
        Collections.sort(sortedList);
        int mid = mid = sortedList.get(sortedList.size() / 2);
        for (Integer val : sortedList) {
            res += Math.abs(val - mid);
        }
        return res;
    }

    public static void main(String[] args) {

    }
}
